/*** 报表处理对象 @param {[msgObj]} prcscd 为处理码,operid 操作人ID,msgObj 发送的JSON对象(可选) */  
function msgTool(url,msgObj){ 
	this._url = url;
	if(msgObj!=null){
		this._msgObj = msgObj;
	}else{
		this._msgObj = new Object();	
	}
}
var indexa;
msgTool.prototype = {
		_errorcode:"1000",  
		/** 发送报文字符串 **/
		_rsgStr:"",
		/*** 设置向后台发送的key,value * @param {key,value}  */  
		setMsg:function(url,sendStr,groupCode){
			this._sendStr = sendStr;
			this._url = url;
			this._groupCode = groupCode;
		},
		setFiledValue:function (key,value){
			this._msgObj[key] = value;
		},
		/*** 向后台的报文转化成字符串 * @param {key,value}  */  
		toString:function(obj){
			return JSON.stringify(this._msgObj);   
		}, 
		//发送报文 *@param{url,bodyObj,callback)}  *url:请求地址 *bodyObj:请求数据 *callback:回调函数
		sendMsg:function(url,bodyObj,callback){
			 
			this._msgObj = JSON.stringify({"head":{},"body":bodyObj});
 			this._url = path+url;
			var ttkn2 = getCookie("ttkn2");
 			$.ajax({
				type:"POST",//提交数据的类型 POST GET
				url:this._url,
				headers:{
					"infoq":"ch=eshop;e=p",
					"ttkn2":ttkn2
				},
				data:this._msgObj,  //提交的数据
				async:true,
				timeout : 600000, //超时时间设置，单位毫秒
				datatype: "text",//"xml", "html", "script", "json", "jsonp", "text".
				//在请求之前调用的函数
				beforeSend:function(){
					indexa= layer.load(0, { shade: false });
				},
				success:function(data){ //成功返回之后调用的函数  
  					//closeLoding();
					layer.close(indexa);
					var rsObj = null;
					if(msg.isJson(data)){
						rsObj = data 
					}else{
						rsObj = JSON.parse(data);   	
					}
					var retCode = rsObj.head.retCode;
					var retMsg = rsObj.head.retMsg; 
  					if(rsObj.head.ttkn2!=null&&rsObj.head.ttkn2!=undefined){
 						setCookie("ttkn2",rsObj.head.ttkn2);//设置token    
					}
					// setCookie("Infoq","ch=ebank;e=p");//设置token
					if(retCode !='0000'){ 
						if(retCode == '0005'){
							layer.confirm(retMsg, {
	 							  icon:2,
								  btn: ['确定'],
	 						 	  title:"温馨提醒",
								}, function(index, layero){
									window.top.location.href=path+'/page/login/loginWechat.do';
								});
						}else{
							layer.alert(retMsg);
						}
						return '';
					} 
					if(callback!=undefined) 	callback(rsObj);
					return rsObj;
				},
 				error: function(){ //调用出错执行的函数   //请求出错处理
 					layer.close(indexa);
 					layer.alert("请检查网络问题！")
					return ;
				}
			});
		},
		// 弹出错误对话框
		showErrorMsg:function(msg){
			//$.messager.alert('温馨提示',msg,'error');
		},
		showAlert:function(msg){
			//$.messager.alert('温馨提示',msg);
		},
		showloading:function(id,msg){

		},
		hideloading:function(id){

		},isJson:function(obj){
			var isjson = typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length; 
			return isjson;
		}
}
function reLogin(msg){
 }

function setCookie(name,value) 
{ 
	var Days = 30; 
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000); 
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
} 

function getCookie(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;

}